﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RzCorportativo.Views
{
    public partial class GeralCurriculo : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.NomeCargo.Attributes.Add("url", this.ResolveUrl("~/Views/Cadastros/Curriculo.aspx/ListarCargos"));
                if (AppSession.Login != null && AppSession.Login.TipoLogin == Lib.TipoLogin.Empresa)
                {
                    this.NomeCargo.Attributes["placeholder"] = "Cargo";
                    this.NomeCargo.Attributes["title"] = "Cargo";
                    this.PretencaoSalarial.Attributes["placeholder"] = "Remuneração";
                    this.PretencaoSalarial.Attributes["title"] = "Remuneração";
                    return;
                }
                var curriculo = Lib.Curriculo.Listar(new Lib.Curriculo()
                {
                    UsuarioId = (AppSession.Login.Usuario ?? new Lib.Usuario()).UsuarioId
                }).FirstOrDefault() ?? new Lib.Curriculo();
                var lista = curriculo.Cargos;
                if (lista != null)
                    foreach (var item in lista)
                    {
                        var row = new System.Web.UI.HtmlControls.HtmlTableRow();
                        row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                        {
                            InnerText = (item ?? new Lib.Cargo()).Nome
                        });
                        row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                        {
                            InnerHtml = "<input type='button' id='btnRemoveCargo" + item.CargoId.ToString() + "$" + curriculo.CurriculoId +
                            "' onclick='RemoveItemCargo(" + item.CargoId.ToString() +
                            "," + curriculo.CurriculoId +
                            ", this)' class='btn btn-danger' value='remover'/>"
                        });
                        row.Attributes.Add("CargoCurriculoId", item.CargoId.ToString() + "$" + curriculo.CurriculoId);
                        this.gridCargoPretendido.Rows.Add(row);
                    }
            }

        }

        internal void LoadModel(Lib.Curriculo __curriculo)
        {
            if (__curriculo == null)
                return;
            this.PretencaoSalarial.Text = __curriculo.PretencaoSalarial.ToString("N2").Replace(".", string.Empty);
            this.DisponibilidadeHorario.SelectedValue = __curriculo.DisponibilidadeHorario.ToString();

        }

        internal void LoadModel(Lib.Vaga vaga)
        {
            if (vaga == null)
                return;
            this.PretencaoSalarial.Text = (vaga.SalarioOferecido ?? 0).ToString("N2").Replace(".", string.Empty);
            this.DisponibilidadeHorario.SelectedValue = vaga.Disponibilidade.ToString();
            this.NomeCargo.Text = (vaga.Cargo ?? new Lib.Cargo()).Nome;
            this.CargoId.Value = vaga.CargoId.ToString();
            this.QtdVagas.Text = vaga.QtdVagas.ToString();
            this.Observacoes.Text = vaga.Observacoes;
            this.TipoVaga.SelectedValue = vaga.TipoVaga;
            this.DataInicioInscricao.Text = vaga.DataInicioInscricao.ToString("dd/MM/yyyy");
            this.DataFimInscricao.Text = vaga.DataFimInscricao.ToString("dd/MM/yyyy");
        }
    }
}